
<?php
/* *
 * 功能：访问另外一个支付系统生成支付订单，这种野路子无法实现支付完成后通知用户。单向支付
 * keller.zhou 支付功能api，接收参数：order_name订单名称， order_price 订单金额， order_type支付类型， extension："备注"
 * 以下代码只是为了方便商户测试而提供的样例代码，商户可以根据自己网站的需要，按照技术文档编写,并非一定要使用该代码。
 * 该代码仅供学习和研究支付宝接口使用，只是提供一个参考。
 */
header('Content-Type: text/html;charset=utf-8');
header('Access-Control-Allow-Origin:*'); // *代表允许任何网址请求
header('Access-Control-Allow-Methods:POST,GET,OPTIONS,DELETE'); // 允许请求的类型
header('Access-Control-Allow-Credentials: true'); // 设置是否允许发送 cookies
header('Access-Control-Allow-Headers: Content-Type,Content-Length,Accept-Encoding,X-Requested-with, Origin'); // 设置允许自定义请求头的字段


function do_get($url) {;
	$ch = curl_init ();
	curl_setopt ( $ch, CURLOPT_URL, $url );
	curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
	curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, 'GET' );
	curl_setopt ( $ch, CURLOPT_TIMEOUT, 60 );
	$result = curl_exec ( $ch );
	curl_close ( $ch );        return $result;
}

function send_post($url, $post_data)
{
	$postdata = http_build_query($post_data);
	$options = array(
		'http' => array(
			'method' => 'POST',
			'header' => 'Content-type:application/x-www-form-urlencoded',
			'content' => $postdata,
			'timeout' => 15 * 60 // 超时时间（单位:s）
		)
	);
	$context = stream_context_create($options);
	$result = file_get_contents($url, false, $context);
	return $result;

}


function send_post_json($url, $post_data)
{
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_HTTPHEADER, array(
			'Content-Type: application/json; charset=utf-8',
			'Content-Length: ' . strlen($post_data)
		)
	);
	$response = curl_exec($ch);
	$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
	curl_close($ch);

	return array($httpCode, $response);

}


//用户id
$user_id= $_GET['user_id'];
//用户名
$user_name= $_GET['user_name'];


//订单号自动生成，随机数+时间戳， 唯一就行
$order_id = 'userid('.$user_id.')_'.$user_name.'_'.strval(time());
//支付类型，alipay   wechat
$order_type = $_GET['order_type'];
//支付金额， order_price, 小数保留2位
$order_price = $_GET['order_price'];

$order_price = number_format($order_price,'2');

//支付名称:17612162770 体验卡7天
$order_name = $_GET['order_name'];

//支付成功回调，暂时没用
$redirect_url = 'http://tmsj.taomiwo.top/pay/notify.php?user_id='.$user_id.'&c_type='.$order_price;
//扩展信息,暂时没用
$extension = '';

//非常重要别泄漏，支付鉴权
$secret = 'zkl';
//
//计算签名sign
$sign = md5(md5($order_id.$order_price).$secret);

$pay_host = 'http://pay.taomiwo.top/api/order';

$data = [order_id => $order_id, order_type => $order_type, order_price => $order_price, order_name => $order_name, redirect_url => $redirect_url, extension => $extension, sign => $sign];


$createPayOrder = send_post($pay_host, $data);

echo $createPayOrder;


?>
